<template>
  <view class="container" v-if="cart.length !== 0">
    <!-- 收货地址组件 -->
    <my-address></my-address>
    
    
    <!-- 商品列表标题 -->
    <view class="cart-title">
      <uni-icons type="shop-filled" size="18"></uni-icons>
      <text class="cart-title-text">购物车</text>
    </view>

    <!-- 渲染商品 -->

    <uni-swipe-action>
      <block v-for="(item, index) in cart" :key="index">
        <uni-swipe-action-item :right-options="options" @click="swiperItemClickHandler(item)">
          <my-goods @num-change="numberChangeHandle" showNum :item="item" @radio-change="radioChange" showRadio></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    
    <!-- 结算组件 -->
    <my-settle></my-settle>
  </view>
    
  <!-- 购物车没有商品时 -->
  <view class="empty-cart" v-else>
    <image src="../../static/cart_empty@2x.png" class="empty-img"></image>
    <text class="tip-text">空空如也</text>
  </view>
</template>

<script>
import badge from '@/mixins/tabbar-badge.js';
import { mapState, mapMutations } from 'vuex';
export default {
  mixins: [badge],
  data(){
    return {
      options:[{
        text:'删除',
        style:{
          backgroundColor:'#c00000'
        }
      }]
    }
  },
  computed: {
    ...mapState('cart', ['cart'])
  },
  methods: {
    ...mapMutations('cart', ['updateGoodsState', 'updateGoodsCount','removeGoodsById']),
    radioChange(e) {
      this.updateGoodsState(e);
    },
    numberChangeHandle(e) {
      this.updateGoodsCount(e);
    },
    swiperItemClickHandler(e){
      this.removeGoodsById(e)
    }
  }
};
</script>

<style lang="scss">
.cart-title {
  height: 40px;
  display: flex;
  align-items: center;
  padding-left: 5px;
  border-bottom: 1px solid #efefef;
  .cart-title-text {
    font-size: 14px;
  }
}
.container{
  padding-bottom: 50px;
}

.empty-cart{
  display: flex;
  flex-direction: column;
  align-items: center;
  .empty-img{
    padding-top: 150px;
    width: 90px;
    height: 90px;
  }
  
  .tip-text{
    font-size: 12px;
    color: gray;
    margin-top: 15px;
  }
}
</style>
